package edu.fdzc.system.controller;

import com.github.pagehelper.PageInfo;
import edu.fdzc.system.common.Result;
import edu.fdzc.system.entity.QuestionType;
import edu.fdzc.system.service.QuestionTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/questionType")
public class QuestionTypeController {

    @Autowired
    private QuestionTypeService questionTypeService;

    @PostMapping("/add")
    public Result add(@RequestBody QuestionType questionType) {
        questionTypeService.add(questionType);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody QuestionType questionType) {
        questionTypeService.updateById(questionType);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        questionTypeService.deleteById(id);
        return Result.success();
    }

    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        questionTypeService.delectBatch(ids);
        return Result.success();
    }

    @GetMapping("/select/{id}")
    public Result selectById (@PathVariable Integer id) {
        QuestionType questionType = questionTypeService.selectById(id);
        return Result.success(questionType);
    }

    @GetMapping("/selectAll")
    public Result selectAll(QuestionType questionType) {
        List<QuestionType> questionTypes = questionTypeService.selectAll(questionType);
        return Result.success(questionTypes);
    }

    @GetMapping("/selectPage")
    public Result selectPage(QuestionType questionType,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<QuestionType> pageInfo = questionTypeService.selectPage(questionType,pageNum,pageSize);
        return Result.success(pageInfo);
    }

}
